const loadRequest = () => {
  return new Promise((resolve, reject) => {
    window.setTimeout(() => {
      resolve({
        isLogin: true,
        nickname: 'test',
        avator: 'http://www.baidu.com'
      })
    }, 3000)
  })
}
export const login = (payload) => {
  // 通过中间介做异步操作
  return async (dispatch) => {
    dispatch(update({isLoading: true}))
    // 异步操作
    let res = await loadRequest()
    dispatch(update({
      isLoading: false,
      ...res,
      ...payload
    }))
  }
  // return {
  //   payload,
  //   type: 'USER_LOGIN'
  // }
}
export const logout = (payload) => {
  return {
    payload,
    type: 'USER_LOGOUT'
  }
}
export const update = (payload) => {
  return {
    payload,
    type: 'USER_UPDATE'
  }
}